package com.zyx.javademo.jsoup;

import com.zyx.javademo.bean.CcassBean;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.URL;

/**
 * @author Yaxi.Zhang
 * @since 2021/8/10 18:25
 * desc: 爬取ccass数据
 */
public class GetCcassDemo {
    public static void main(String[] args) throws IOException {
        // 准备抓取的目标地址
        String url = "https://webb-site.com/ccass/cholder.asp?sort=stakdn&part=1456&d=2021-08-10";
        // 解析网址
        Document document = Jsoup.parse(new URL(url).openStream(), "UTF-8", url);
        // 获取所需数据
        Elements elements = document.getElementsByClass("optable");
        // 解析数据
        for (Element element : elements.get(0).getElementsByTag("tr")) {
            Elements tds = element.getElementsByTag("td");
            if (tds.size() == 8) {
                CcassBean ccassBean = new CcassBean(tds.get(0).text(),
                        tds.get(1).text(),
                        tds.get(2).text(),
                        tds.get(3).text(),
                        tds.get(4).text(),
                        tds.get(6).text(),
                        tds.get(7).text());
                System.out.println(ccassBean);
            }
        }
    }
}